package com.salestax.core.specific.tax;

import java.math.BigDecimal;
import java.math.RoundingMode;

import com.salestax.core.Product;
import com.salestax.core.Tax;

public class SalesTax extends Tax {

	private BigDecimal rate;


	public SalesTax(double rate) {
		this.rate = new BigDecimal(rate);
	}


	@Override
	public BigDecimal calculateTax(Product product) {
		assert product != null;
		BigDecimal percentage = rate.divide(new BigDecimal(100));
		BigDecimal result =  product.getBasePrice().multiply(percentage);
		return new BigDecimal(Math.ceil(result.doubleValue() * 20) / 20).setScale(2, RoundingMode.HALF_UP);
		
	}
	
	public static void main(String[] args) {
		BigDecimal rate = new BigDecimal(5);
		BigDecimal percentage = rate.divide(new BigDecimal(100));
	//	BigDecimal result =  product.getBasePrice().multiply(percentage);
	//	return new BigDecimal(Math.ceil(result.doubleValue() * 20) / 20).setScale(2, RoundingMode.HALF_UP);
		
	}

}
